package cn.com.nes.site.action.crm;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.crm.OldProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller("product")
@RequestMapping("/product")
public class ProductAction {
	@Resource
	private OldProductService service;
	
	//获取产品列表
    @RequestMapping(method = RequestMethod.POST, value = "/getProductList")
    public @ResponseBody
    PageData getProductList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getProductList(req) ;
        return res;
    }
    
    //保存产品
    @RequestMapping(method = RequestMethod.POST, value = "/saveProduct")
    public @ResponseBody
    PageData saveProduct(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveProduct(req) ;
        return res;
    }
    
    //删除产品
    @RequestMapping(method = RequestMethod.POST, value = "/delProduct")
    public @ResponseBody
    PageData delProduct(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delProduct(req) ;
        return res;
    }
    
    //获取价格列表
    @RequestMapping(method = RequestMethod.POST, value = "/getPriceList")
    public @ResponseBody
    PageData getPriceList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getPriceList(req) ;
        return res;
    }
    
    //保存价格
    @RequestMapping(method = RequestMethod.POST, value = "/savePrice")
    public @ResponseBody
    PageData savePrice(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.savePrice(req) ;
        return res;
    }
    
    //删除价格
    @RequestMapping(method = RequestMethod.POST, value = "/delPrice")
    public @ResponseBody
    PageData delPrice(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delPrice(req) ;
        return res;
    }
    
    //获取产品价格列表
    @RequestMapping(method = RequestMethod.POST, value = "/getProductPriceList")
    public @ResponseBody
    PageData getProductPriceList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getProductPriceList(req) ;
        return res;
    }
    
    //保存产品价格
    @RequestMapping(method = RequestMethod.POST, value = "/saveProductPrice")
    public @ResponseBody
    PageData saveProductPrice(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveProductPrice(req) ;
        return res;
    }
    
    //删除产品价格
    @RequestMapping(method = RequestMethod.POST, value = "/delProductPrice")
    public @ResponseBody
    PageData delProductPrice(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delProductPrice(req) ;
        return res;
    }
    
    @RequestMapping(method = RequestMethod.POST, value = "/getJglxList")
    public @ResponseBody
    PageData getJglxList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getJglxList(req) ;
        return res;
    }
    
    @RequestMapping(method = RequestMethod.POST, value = "/getCpmcList")
    public @ResponseBody
    PageData getCpmcList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCpmcList(req) ;
        return res;
    }
}
